<template>
  <div class="account-table-wrap">
    <el-table
      :data="tableData"
      style="width: 100%"
      :border="true"
      :fit="true"
      :stripe="true"
      size="mini"
      align="center">
      <el-table-column
        prop="id"
        label="id"
        min-width="100"
        align="center">
      </el-table-column>

      <el-table-column
        prop="number"
        label="分类编号"
        min-width="180"
        align="center">
      </el-table-column>

      <el-table-column
        prop="class_name"
        label="名称"
        min-width="180"
        align="center">
      </el-table-column>

      <el-table-column
        prop="count"
        label="产品数量"
        min-width="120"
        align="center">
      </el-table-column>

      <el-table-column
        prop="order"
        label="权重"
        min-width="120"
        align="center">
      </el-table-column>
      <el-table-column label="操作"
      min-width="180"
      align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            plain
            type="primary"
            @click="tableEdit(scope.row)">编辑</el-button>
          <el-button
            size="mini"
            plain
            type="danger"
            @click="tableDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <deleteConfirm v-if="showMask" @closeDelete="closeDelete" @deleteConfirm="deleteConfirm"></deleteConfirm>
  </div>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import { Prop, Emit } from 'vue-property-decorator';
import deleteConfirm from '@/components/deleteConfirm.vue';
import ajaxResquest from '@/api/apiRequest';
@Component({
  components: {
    deleteConfirm
  }
})
export default class AccountListTable extends Vue {
  // tableData: Array<any> = [];
  @Prop({
    type: Array
  })
  tableData!: any[];
  showMask: boolean = false;
  deleteId!: number;
  deleteRes!: ajaxResquest;
  tableEdit(row: any) {
    this.$to('produceCategoryCreate', { edit: true, id: row.id });
  }
  mounted() {
    this.deleteRes = new ajaxResquest('/goods/delClass');
  }
  tableDelete(row: any) {
    console.log(row);
    this.deleteId = row.id;
    this.showMask = true;
  }
  closeDelete(row: object) {
    this.showMask = false;
  }
  deleteConfirm() {
    console.log('done');
    this.deleteRes.getFunction({ classId: this.deleteId }).then((res:any) => {
      if (res.data.code === 1) {
        this.getData();
        this.showMask = false;
      }
    });
  }
  @Emit('getData')
  getData() {}
}
</script>
<style>
.account-table-wrap {
}
</style>
